package com.taptech.doufu.util;

import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;

public class AnimationUtil
{

	/**
	 * 献花动画
	 */
	public static void flowerAnimation(final View view)
	{
		ScaleAnimation sa = new ScaleAnimation(0.8f, 1.0f, 0.8f, 1.0f, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0.5f);
		AlphaAnimation aa = new AlphaAnimation(0.8f, 0f);

		TranslateAnimation translateAnimationX = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_SELF, 0.1f, TranslateAnimation.RELATIVE_TO_SELF,
				TranslateAnimation.RELATIVE_TO_SELF + 1.5f, TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0);
		translateAnimationX.setFillAfter(true);
		TranslateAnimation translateAnimationY = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0,
				TranslateAnimation.RELATIVE_TO_SELF, 0.1f, TranslateAnimation.RELATIVE_TO_SELF, TranslateAnimation.RELATIVE_TO_SELF - 2.5f);
		AnimationSet set = new AnimationSet(false);
		set.addAnimation(aa);
		set.addAnimation(sa);
		set.addAnimation(translateAnimationX);
		set.addAnimation(translateAnimationY);
		set.setDuration(1000);
		set.setFillAfter(true);
		set.setAnimationListener(new AnimationListener()
		{
			@Override
			public void onAnimationStart(Animation animation)
			{
			}

			@Override
			public void onAnimationRepeat(Animation animation)
			{
			}

			@Override
			public void onAnimationEnd(Animation animation)
			{
				view.setVisibility(View.GONE);
			}
		});
		view.startAnimation(set);
	}

	public static void starAlphaAnimation(final View view, int startOffset)
	{
		AlphaAnimation aa = new AlphaAnimation(1.0f, 0f);
		AnimationSet set = new AnimationSet(false);
		set.addAnimation(aa);
		set.setStartOffset(startOffset);
		set.setDuration(1000);
		set.setAnimationListener(new AnimationListener()
		{
			@Override
			public void onAnimationStart(Animation animation)
			{
			}

			@Override
			public void onAnimationRepeat(Animation animation)
			{
			}

			@Override
			public void onAnimationEnd(Animation animation)
			{
				view.setVisibility(View.GONE);

			}
		});
		view.startAnimation(set);
	}

	/**
	 * 首页ugc与文评的弹出动画效果
	 * 
	 * @param view
	 * @param scalePro
	 * @param startOffset
	 */
	public static void starShockLoopAnimationLong(final View view, final float scalePro, int startOffset)
	{
		final AnimationSet loopSmall = new AnimationSet(true);
		ScaleAnimation loopScale = new ScaleAnimation(1f, scalePro, 1f, scalePro, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		AlphaAnimation loopAlpha = new AlphaAnimation(1f, scalePro);
		loopSmall.addAnimation(loopScale);
		loopSmall.addAnimation(loopAlpha);
		loopSmall.setDuration(1000);
		loopSmall.setAnimationListener(new AnimationListener()
		{
			@Override
			public void onAnimationStart(Animation animation)
			{
			}

			@Override
			public void onAnimationRepeat(Animation animation)
			{
			}

			@Override
			public void onAnimationEnd(Animation animation)
			{
				AnimationSet loopBig = new AnimationSet(true);
				ScaleAnimation loopScale = new ScaleAnimation(scalePro, 1f, scalePro, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
				AlphaAnimation loopAlpha = new AlphaAnimation(scalePro, 1f);
				loopBig.addAnimation(loopScale);
				loopBig.addAnimation(loopAlpha);
				loopBig.setDuration(1000);
				view.startAnimation(loopBig);
				loopBig.setAnimationListener(new AnimationListener()
				{
					@Override
					public void onAnimationStart(Animation animation)
					{
					}

					@Override
					public void onAnimationRepeat(Animation animation)
					{
					}

					@Override
					public void onAnimationEnd(Animation animation)
					{
						view.startAnimation(loopSmall);
					}
				});
			}
		});

		ScaleAnimation scale = new ScaleAnimation(0f, 1f, 0f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		scale.setStartOffset(startOffset);
		scale.setDuration(50);
		view.startAnimation(scale);// 动画开始执行
		scale.setAnimationListener(new AnimationListener()
		{
			@Override
			public void onAnimationStart(Animation animation)
			{
			}

			@Override
			public void onAnimationRepeat(Animation animation)
			{
			}

			@Override
			public void onAnimationEnd(Animation animation)
			{
				ScaleAnimation scale = new ScaleAnimation(1f, scalePro, 1f, scalePro, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
				scale.setDuration(50);
				view.startAnimation(scale);
				scale.setAnimationListener(new AnimationListener()
				{
					@Override
					public void onAnimationStart(Animation animation)
					{
					}

					@Override
					public void onAnimationRepeat(Animation animation)
					{
					}

					@Override
					public void onAnimationEnd(Animation animation)
					{
						ScaleAnimation scale = new ScaleAnimation(scalePro, 1f, scalePro, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
								0.5f);
						scale.setDuration(50);
						view.startAnimation(scale);
						scale.setAnimationListener(new AnimationListener()
						{
							@Override
							public void onAnimationStart(Animation animation)
							{
							}

							@Override
							public void onAnimationRepeat(Animation animation)
							{
							}

							@Override
							public void onAnimationEnd(Animation animation)
							{
								view.startAnimation(loopSmall);
							}
						});
					}
				});
			}
		});
	}

}
